import os
import json


inputFile = 'data\lzf.100.标注.jsonl'
output = "data\lzf.100.标注.txt"


with open(inputFile, 'r+', encoding='utf-8') as f:
    data = f.readlines()
    
    for index, line in enumerate(data):
        line_js = json.loads(line)
        print(line_js)
        answerable = line_js['answerable']
        with open(output, 'a', encoding='utf-8') as w:
            if answerable == 'Y':
                w.write('<O>' + line_js['question'] + '<\\O>' + '\n')
            else:
                w.write('<O>' + line_js['question'] + '<\\O>' + '!\n')
            if answerable == 'Y':
                w.write('<Q>' + line_js['Q'] + '<\\Q>'  + '\n')
            else:
                w.write('<Q>' + line_js['Q'] + '<\\Q>' + '!\n')
                
            candidates = line_js['candidates']
            if len(candidates) != 0:
                w.write('<1>' + candidates[0]['question'] + '<\\1>' + candidates[0]['judgeScore'] + '\n')
                w.write('<2>' + candidates[1]['question'] + '<\\2>' + candidates[1]['judgeScore'] +  '\n')
                w.write('<3>' + candidates[2]['question'] + '<\\3>' + candidates[2]['judgeScore'] + '\n\n')
            else:
                w.write('<1>' + '<\1>' + '\n')
                w.write('<2>' + '<\2>' + '\n')
                w.write('<3>' + '<\3>' + '\n\n')

